using UnityEngine;
using System.Collections;

public class fireballScript : MonoBehaviour {
	public float life = 0.0f;
	public Vector3 dir, dir2, last, current;
	public Transform after;
	// Use this for initialization
	void Start () {
		last = new Vector3(99999.0f,99999.0f,99999.0f);
	}
	
	// Update is called once per frame
	void Update () {
		life += Time.deltaTime;
		if(life > 4 ){
			GameObject.Destroy(gameObject);
		}
		dir2 = dir * 200 * Time.deltaTime;
		transform.Translate(dir2.x, dir2.y, dir2.z, Space.World);
	}
	void OnTriggerEnter(Collider other){
		EnemyHealth e = other.GetComponent<EnemyHealth>();
		if(e != null){
			e.damage(20.0f);
			Network.Instantiate(after,transform.position,transform.rotation,0);
			GameObject.Destroy(gameObject);
		}
		/*PlayerScript p = other.GetComponent<PlayerScript>();
		if(p == null){
			if(other.name != "fireballPickup" || other.name != "fireballPickup(Clone)" || other.name != "spinPickup" || other.name != "spinPickup(Clone)" || other.name != "Water Pickup" || other.name != "Water Pickup(Clone)"){
				print(other.name);
				Network.Instantiate(after,transform.position,transform.rotation,0);
				GameObject.Destroy(gameObject);
			}
		}*/
	
	}
	public void setDir(Vector3 d){
		networkView.RPC("setFireballDirection",RPCMode.All,d);
	}
	[RPC]
	void setFireballDirection(Vector3 d){
		dir = d;
	}
}
